$(document).ready(function(){
	$('#add_department').click(function(){		
		if ($('#department_name').value != '') {
			addDepartment();
		}
	});
	
	$('#add_room').click(function(){		
		if ($('#room_name').value != '') {
			addRoom();
		}
	});	
	
	$('.nav_bg a').click(function() {
		$('.nav_bg a').removeClass('active');
		$(this).addClass('active');
	});
	
	$('select#filter_department').change(function() {
		getAllRoomsTable();
	});
	
	$('#addBed').click(function() {
		addBed();
	});
	
	$('#searchBed').click(function() {
		getAllBedsTable();
	});
});

function getAllDepartmentsTable(){
	$('#error_department').html('');
	$.get(
		'../Department/getAllDepartmentsTable?set_ajax_view',
		{
		},
		function(data){
			$('table#departmentTable tbody').append(data);
			styleTable($('table#departmentTable')); 
		}
	);
};

function getAllRoomsTable(){
	$('#error_room').html('');
	$.get(
		'../Department/getAllRoomsTable?set_ajax_view',
		{
		filter_department: $('select#filter_department').val()
		},
		function(data){
			$('table#roomTable tbody').html(data);
			styleTable($('table#roomTable'));
		}
	);
};

function getRoomTypeSelect() {
	$.get(
			'../Department/getRoomTypesSelect?set_ajax_view',
			{			
			},
			function(data){
				$('select#roomType').html("<option id='empty' value='empty'>" + _("Select room type") + "</option>");				
				$('select#roomType').append(data);
			}
		);
}

function getAllDepartmentsSelect(){
	$('#error_department').html('');
	$.get(
		'../Department/getAllDepartmentsSelect?set_ajax_view',
		{
		},
		function(data){
			$('select#room_department').html("<option id='empty' value='empty'>" + _("Select department") + "</option>");
			$('select#room_department').append(data);
			$('select#filter_department').html("<option selected id='all' value='all'>" + _("All departments") + "</option>");
			$('select#filter_department').append(data);
			$('select#filter_department').append("<option id='other' value='other'>" + _("Other") + "</option>");
		}
	);
};

function addDepartment(){
	$('#error_department').html('');
	var depName = $('#department_name').val();
	if (depName.split(' ').join('') == '') {
		$('#error_department').html("<font color='red'>" + _("Please input department name") + "</font>");
	} else {
		$.get(
			'../Department/addDepartment?set_ajax_view',
			{
			department_name: $('#department_name').val(),
			department_description: $('#department_description').val()
			},
			function(data){
				$('table#departmentTable tbody').append(data);
				$('#department_name').val('');
				$('#department_description').val('');
				getAllDepartmentsSelect();
			}
		);
	}
};

function addRoom(){	
	$('#error_room').html('');
	var roomName = $('#room_name').val();
	if (roomName.split(' ').join('') == '') {
		$('#error_room').html("<font color='red'>" + _("Please input room name") + "</font>");
	} else {
		$.get(
			'../Department/addRoom?set_ajax_view',
			{
			room_department: $('#room_department').val(),
			room_name: $('#room_name').val(),
			room_description: $('#room_description').val(),
			encounter_room: $('#encounter_room').attr('checked'),
			room_type: $('select#roomType option:selected').val()
			},
			function(data){
				$('table#roomTable tbody').append(data);
				$('#room_name').val('');
				$('#room_description').val('');
			}
		);
	}
};

function editDepartment(departmentId){
	$('#error_department').html('');
	$('#department_' + departmentId + '_name_input').val($('#department_' + departmentId + '_name_span').html());
	$('#department_' + departmentId + '_description_input').val($('#department_' + departmentId + '_description_span').html());
	$('#department_' + departmentId + '_name_span').hide();
	$('#department_' + departmentId + '_description_span').hide();
	$('#department_' + departmentId + '_edit').hide();
	$('#department_' + departmentId + '_name_input').show();
	$('#department_' + departmentId + '_description_input').show();
	$('#department_' + departmentId + '_save').show();
	$('#department_' + departmentId + '_cancel').show();
	getAllDepartmentsSelect();
}

function editRoom(roomId){
	$('#error_room').html('');
	// Get value for room_department
	$.get(
		'../Department/getAllRoomDepartments?set_ajax_view',
		{
		room_id: roomId
		},
		function(data){
			$('select#room_' + roomId + '_department_select').html("<option id='empty' value='empty'>" + _("Select department") + "</option");
			$('select#room_' + roomId + '_department_select').append(data);
		}
	);
	// Get value for room_type
	$.get(
		'../Department/getRoomTypesSelect?set_ajax_view',
		{
		room_id: roomId
		},
		function(data) {
			$('select#room_' + roomId + '_room_type_select').html("<option id='empty' value='empty'>" + _("Select room type") + "</option");
			$('select#room_' + roomId + '_room_type_select').append(data);
		}
	);
	
	$('#room_' + roomId + '_name_input').val($('#room_' + roomId + '_name_span').html());
	$('#room_' + roomId + '_description_input').val($('#room_' + roomId + '_description_span').html());
	$('#room_' + roomId + '_name_span').hide();
	$('#room_' + roomId + '_description_span').hide();
	$('#room_' + roomId + '_department_span').hide();
	$('#room_' + roomId + '_encounter_room_span').hide();
	$('#room_' + roomId + '_room_type_span').hide();
	$('#room_' + roomId + '_edit').hide();
	
	
	$('#room_' + roomId + '_name_input').show();
	$('#room_' + roomId + '_description_input').show();
	if ($('#room_' + roomId + '_encounter_room_span').text() == 'Yes') {
		$('#room_' + roomId + '_encounter_room_input').attr('checked', 'checked');
	}
	$('#room_' + roomId + '_encounter_room_input').show();
	$('#room_' + roomId + '_save').show();
	$('#room_' + roomId + '_cancel').show();
	$('#room_' + roomId + '_department_select').show();
	$('#room_' + roomId + '_room_type_select').show();
}

function saveDepartment(departmentId){
	var depName = $('#department_' + departmentId + '_name_input').val();
	if (depName.split(' ').join('') == '') {
		$('#error_department').html("<font color='red'>" + _("Please input department name") + "</font>");
	} else {
		$.post(
			'../Department/saveDepartment?set_ajax_view',
			{
				department_id: departmentId,
				department_name: $('#department_' + departmentId + '_name_input').val(),
				department_description: $('#department_' + departmentId + '_description_input').val()
			},
			function(data){
				$('#department_' + departmentId + '_name_span').html(data.name);
				$('#department_' + departmentId + '_description_span').html(data.description);
				$('#department_' + departmentId + '_name_span').show();
				$('#department_' + departmentId + '_description_span').show();
				$('#department_' + departmentId + '_edit').show();
				$('#department_' + departmentId + '_name_input').hide();
				$('#department_' + departmentId + '_description_input').hide();
				$('#department_' + departmentId + '_save').hide();
				$('#department_' + departmentId + '_cancel').hide();
				getAllDepartmentsSelect();				
			},
			"json"
		);
	}
};

function saveRoom(roomId){	
	var roomName = $('#room_' + roomId + '_name_input').val();
	if (roomName.split(' ').join('') == '') {
		$('#error_room').html("<font color='red'>" + _("Please input room name") + "</font>");
	} else {
		$.post(
			'../Department/saveRoom?set_ajax_view',
			{
				room_id: roomId,
				room_name: $('#room_' + roomId + '_name_input').val(),
				room_description: $('#room_' + roomId + '_description_input').val(),
				room_department: $('#room_' + roomId + '_department_select').val(),
				encounter_room: $('#room_' + roomId + '_encounter_room_input').attr('checked'),
				room_type: $('#room_' + roomId + '_room_type_select option:selected').val()
			},
			function(data){
				$.get(
					'../Department/getDepartmentName?set_ajax_view',
					{
						department_id: $('#room_' + roomId + '_department_select').val()
					},
					function(data){
						$('#room_' + roomId + '_department_span').html(data);
					}
				);
				var roomTypeText = '';
				if ($('#room_' + roomId + '_room_type_select option:selected').val() != 'empty') {
					roomTypeText = $('#room_' + roomId + '_room_type_select option:selected').text();
				}
				$('#room_' + roomId + '_room_type_span').html(roomTypeText);
				
				$('#room_' + roomId + '_name_input').hide();
				$('#room_' + roomId + '_description_input').hide();
				$('#room_' + roomId + '_encounter_room_input').hide();
				$('#room_' + roomId + '_department_select').hide();
				$('#room_' + roomId + '_room_type_select').hide();
				$('#room_' + roomId + '_save').hide();
				$('#room_' + roomId + '_cancel').hide();
								
				if ($('#room_' + roomId + '_encounter_room_input').attr('checked') == true) {
					$('#room_' + roomId + '_encounter_room_span').text(_('Yes')).show();
				} else {
					$('#room_' + roomId + '_encounter_room_span').text(_('No')).show();
				}
				$('#room_' + roomId + '_name_span').html($('#room_' + roomId + '_name_input').val());
				$('#room_' + roomId + '_description_span').html(data.description);
				$('#room_' + roomId + '_name_span').show();
				$('#room_' + roomId + '_description_span').show();
				$('#room_' + roomId + '_department_span').show();
				$('#room_' + roomId + '_room_type_span').show();
				$('#room_' + roomId + '_edit').show();				
			},
			"json"
		);
	}
};
function cancelDepartment(departmentId){
	$('#department_' + departmentId + '_name_span').show();
	$('#department_' + departmentId + '_description_span').show();
	$('#department_' + departmentId + '_edit').show();
	$('#department_' + departmentId + '_name_input').hide();
	$('#department_' + departmentId + '_description_input').hide();
	$('#department_' + departmentId + '_save').hide();
	$('#department_' + departmentId + '_cancel').hide();	
	$('#error_department').html('');
}
function cancelRoom(roomId){
	$('#room_' + roomId + '_name_span').show();
	$('#room_' + roomId + '_description_span').show();
	$('#room_' + roomId + '_department_span').show();
	$('#room_' + roomId + '_encounter_room_span').show();
	$('#room_' + roomId + '_room_type_span').show();
	$('#room_' + roomId + '_edit').show();
	$('#room_' + roomId + '_name_input').hide();
	$('#room_' + roomId + '_description_input').hide();
	$('#room_' + roomId + '_encounter_room_input').hide();
	$('#room_' + roomId + '_department_select').hide();
	$('#room_' + roomId + '_room_type_select').hide();
	$('#room_' + roomId + '_save').hide();
	$('#room_' + roomId + '_cancel').hide();	
	$('#error_room').html('');
}

function removeDepartment(departmentId){
	$('#error_department').html('');
	$.get(
		'../Department/removeOrUndoDepartment?set_ajax_view',
		{
		department_id: departmentId,
		activity: 'remove'
		},
		function(data){
			$('#department_' + departmentId + '_status_span').addClass("impression");
			$('#department_' + departmentId + '_status_span').html('');
			$('#department_' + departmentId + '_status_span').append(_("Temporary delete"));
			$('#department_' + departmentId + '_remove_span').html('');
			$('#department_' + departmentId + '_remove_span').append(
					'<a href="javascript:undoDepartment(' + departmentId + ')" title="' + _("Reuse") + '">'
				+    	'<img src="../images/unlock_small.png" alt="' + _("Reuse") + '"></img>'  
	            + 	'</a>');
			getAllDepartmentsSelect();
		}
	);
};

/**
 * Undo one department.
 * @param deptId The id of department
 */
function undoDepartment(departmentId) {
	$('#error_department').html('');
	$.get(
		'../Department/removeOrUndoDepartment?set_ajax_view',
		{
		department_id: departmentId,
		activity: 'undo'
		},
		function(data) {
			$('#department_' + departmentId + '_status_span').removeClass("impression");
			$('#department_' + departmentId + '_status_span').html('');
			$('#department_' + departmentId + '_status_span').append(_("In Use"));
			$('#department_' + departmentId + '_remove_span').html('');
			$('#department_' + departmentId + '_remove_span').append(
					'<a href="javascript:removeDepartment(' + departmentId + ')" title="' + _("Delete") + '">'
				+    	'<img src="../images/lock_small.png" alt="' + _("Delete") + '"></img>'  
	            + 	'</a>');
		}
	);
}

function removeRoom(roomId){
	$('#error_room').html('');
	$.get(
		'../Department/removeOrUndoRoom?set_ajax_view',
		{
		room_id: roomId,
		activity: 'remove'
		},
		function(data){
			$('#room_' + roomId + '_status_span').addClass("impression");
			$('#room_' + roomId + '_status_span').html('');
			$('#room_' + roomId + '_status_span').append(_("Temporary delete"));
			$('#room_' + roomId + '_remove_span').html('');
			$('#room_' + roomId + '_remove_span').append(
					'<a href="javascript:undoRoom(' + roomId + ')" title="' + _("Reuse") + '">'
				+    	'<img src="../images/unlock_small.png" alt="' + _("Reuse") + '"></img>'  
	            + 	'</a>');
		}
	);
};

function undoRoom(roomId){
	$('#error_room').html('');
	$.get(
		'../Department/removeOrUndoRoom?set_ajax_view',
		{
		room_id: roomId,
		activity: 'undo'
		},
		function(data){
			$('#room_' + roomId + '_status_span').removeClass("impression");
			$('#room_' + roomId + '_status_span').html('');
			$('#room_' + roomId + '_status_span').append(_("In Use"));
			$('#room_' + roomId + '_remove_span').html('');
			$('#room_' + roomId + '_remove_span').append(
					'<a href="javascript:removeRoom(' + roomId + ')" title="' + _("Delete") + '">'
				+    	'<img src="../images/lock_small.png" alt="' + _("Delete") + '"></img>'  
	            + 	'</a>');
		}
	);
};

var curDivId = 'department'
function showOneDiv(divId) {
	if (divId != curDivId) {
		$("#" + curDivId).hide("slow");
		$("#" + divId).show("slow");
		curDivId = divId;
	}
	if (divId == 'room'){
		getAllDepartmentsSelect();
		getRoomTypeSelect();
		getAllRoomsTable();
	} else if (divId == 'bed') {
		getAllDepartmentsSelect();
		getDataToCreateBed();
	}
};


function styleTable(table) {

}

/**
* Prepare data for listbox 'department', 'room' on UI ... to modify some bed. 
*/
function getDataToCreateBed() {
	// refresh to default value
	$('#errorBed').html('');
	$('select#roomOfBed').html("<option id='empty' value='empty'>" + _("Select room") + "</option>");
	$('#bedCode').val('');
    $('#price').val('');
    $('select#filterRoomOfBed').html("<option id='empty' value='empty'>" + _("All rooms") + "</option>");
    $('table#bedTable tbody').html('');
    
	$.ajax ({		
		url:	  	"../Department/getDataToCreateBed?set_ajax_view",
		dataType: 	"json",
		success:  function(data) {
			// departments
			$('select#roomDepartment').html("<option id='empty' value='empty'>" + _("Select department") + "</option>");
			$('select#roomDepartment').append(data.departments);
			// max of patients
			$('select#maxPatients').html("");
			var i = 1;
			for (i = 1; i <= data.maxPatients; i++) {
				$('select#maxPatients').append("<option value='" + i + "'>" + i + "</option>");
			}
			// bed price type
			$('select#bedPriceType').html("");
			$('select#bedPriceType').append(data.priceTypes);
			
			// filter departments
			$('select#filterRoomDepartment').html("<option id='empty' value='empty'>" + _("All departments") + "</option>");
			$('select#filterRoomDepartment').append(data.departments);
		}
	});
}

/**
 * When one department is choosed, list of corresponding rooms is displayed.
 */
function getRoomsSelect(depSelect, roomSelect) {
	$('#errorBed').html('');
	var deptId = $('select#' + depSelect + ' option:selected').val();
	$.get(
		'../Department/getRoomsSelect?set_ajax_view',
		{
		deptId: deptId
		},
		function(data) {
			var text = "";			
			if (roomSelect == 'filterRoomOfBed') {
				text = _("All rooms");				
			} else {
				text = _("Select room");
			}
			$('select#' + roomSelect).html("<option id='empty' value='empty'>" + text + "</option>");
			$('select#' + roomSelect).append(data);
		}
	);
}

/**
 * Create new bed.
 */
function addBed() {
	$('#errorBed').html('');
	// validate before save bed
	if (validateBed('roomDepartment', 'roomOfBed', 'bedCode', 'price')) {
		$.get(
				'../Department/addBed?set_ajax_view',
				{
				deptId: $('select#roomDepartment option:selected').val(),
				roomId: $('select#roomOfBed option:selected').val(),
				bedCode: $.trim($('#bedCode').val()),
				maxPatients: $('select#maxPatients option:selected').val(),
				price: $.trim($('#price').val()),
				priceType: $('select#bedPriceType option:selected').val()
				},
				function(data) {
					if (data == 'existed') {
						$('#errorBed').html("<font color='red'>" + _("Bed code existed") + "</font>");
					} else {
						$('#errorBed').html("<font color='blue'>" + _("Bed created") + "</font>");
						$('#bedCode').val('');
						$('#price').val('');
					}
				}
			);
	}
}

/**
 * Validate one bed before saving it into database.
 * @param deptElem The html element id of department
 * @param roomElem The html element id of room
 * @param codeElem The html element id of bed code
 * @param priceElem The html element id of bed price
 * @return true if validate bed successfully, otherwise return false
 */
function validateBed(deptElem, roomElem, codeElem, priceElem) {
	if ($('select#' + deptElem + ' option:selected').val() == 'empty') {
		$('#errorBed').html("<font color='red'>" + _("Please select department") + "</font>");
		return false;
	}
	if ($('select#' + roomElem + ' option:selected').val() == 'empty') {
		$('#errorBed').html("<font color='red'>" + _("Please select room") + "</font>");
		return false;
	}	
	if ($.trim($('#' + codeElem).val()) == '') {
		$('#errorBed').html("<font color='red'>" + _("Please input bed code") + "</font>");
		return false;
	}
	var price = $('#' + priceElem).val();
	if ($.trim(price) == '') {
		$('#errorBed').html("<font color='red'>" + _("Please input bed price") + "</font>");
		return false;
	}
	if ($.trim(price).length > 0 && !isFloating(price)) {
		$('#errorBed').html("<font color='red'>" + _("Invalid bed price") + "</font>");
		return false;
	}	
	return true;
}

/**
 * List all beds on UI in some department and room. 
 */ 
function getAllBedsTable() {
	$('#errorBed').html('');
	$.get(
		'../Department/getAllBedsTable?set_ajax_view',
		{
		deptId: $('select#filterRoomDepartment option:selected').val(),
		roomId: $('select#filterRoomOfBed option:selected').val()
		},
		function(data) {
			$('table#bedTable tbody').html('');
			if (data == '') {
				$('table#bedTable tbody').append(_("No bed found"));
			} else {
				$('table#bedTable tbody').append(data);
			}
			styleTable($('table#bedTable'));
		}
	);
}

/**
 * Edit a specific bed.
 * @param bedId The id of bed to edit
 */
function editBed(bedId) {
	$('#errorBed').html('');
	
	$.ajax ({		
		url:	  	"../Department/getDataToEditBed?set_ajax_view",
		data:       "bedId=" + bedId,
		dataType: 	"json",
		success:  function(data) {
			// departments
			$('select#bed_' + bedId + '_department_select').html("<option id='empty' value='empty'>" + _("Select department") + "</option>");
			$('select#bed_' + bedId + '_department_select').append(data.departments);
			// rooms 
			$('select#bed_' + bedId + '_room_select').html("<option id='empty' value='empty'>" + _("Select room") + "</option>");
			$('select#bed_' + bedId + '_room_select').append(data.rooms);
			
			// max of patients
			$('select#bed_' + bedId + '_maxPatients_select').html("");
			$('select#bed_' + bedId + '_maxPatients_select').append(data.maxPatients);
			
			// bed price type
			$('select#bed_' + bedId + '_priceType_select').html("");
			$('select#bed_' + bedId + '_priceType_select').append(data.priceTypes);
						
		}
	});
	
	$('#bed_' + bedId + '_code_input').val($('#bed_' + bedId + '_code_span').html());
	$('#bed_' + bedId + '_price_input').val($('#bed_' + bedId + '_price_span').html());
	// hide element
	$('#bed_' + bedId + '_department_span').hide();
	$('#bed_' + bedId + '_room_span').hide();
	$('#bed_' + bedId + '_code_span').hide();
	$('#bed_' + bedId + '_maxPatients_span').hide();
	$('#bed_' + bedId + '_price_span').hide();
	$('#bed_' + bedId + '_priceType_span').hide();
	$('#bed_' + bedId + '_edit').hide();
	
	// show element
	$('#bed_' + bedId + '_department_select').show();
	$('#bed_' + bedId + '_room_select').show();
	$('#bed_' + bedId + '_code_input').show();
	$('#bed_' + bedId + '_maxPatients_select').show();
	$('#bed_' + bedId + '_price_input').show();
	$('#bed_' + bedId + '_priceType_select').show();
	$('#bed_' + bedId + '_save').show();
	$('#bed_' + bedId + '_cancel').show();
}

/**
 * Save bed after modify.
 * @param bedId The id of modified bed
 */
function saveBed(bedId) {
	$('#errorBed').html('');
	// validate before save bed
	var deptElem = 'bed_' + bedId + '_department_select';
	var roomElem = 'bed_' + bedId + '_room_select';
	var codeElem = 'bed_' + bedId + '_code_input';
	var priceElem = 'bed_' + bedId + '_price_input';
	var maxPatientsElem = 'bed_' + bedId + '_maxPatients_select';
	var priceTypeElem = 'bed_' + bedId + '_priceType_select';
	
	if (validateBed(deptElem, roomElem, codeElem, priceElem)) {		
		$.get(
				'../Department/saveBed?set_ajax_view',
				{
				bedId: bedId,
				deptId: $('select#' + deptElem + ' option:selected').val(),
				roomId: $('select#' + roomElem + ' option:selected').val(),
				bedCode: $.trim($('#' + codeElem).val()),
				maxPatients: $('select#' + maxPatientsElem + ' option:selected').val(),
				price: $.trim($('#' + priceElem).val()),
				priceType: $('select#' + priceTypeElem + ' option:selected').val()
				},
				function(data) {
					if (data == 'existed') {
						$('#errorBed').html("<font color='red'>" + _("Bed code existed") + "</font>");
					} else {
						$('tr#' + bedId).html("");
						$('tr#' + bedId).append(data);
						styleTable($('table#bedTable'));
					}													
				}
			);
	}
}
 
/**
 * Cancel modification one bed.
 * @param bedId The id of bed
 */
function cancelBed(bedId) {
	$('#errorBed').html('');
	// hide element
	$('#bed_' + bedId + '_department_select').hide();
	$('#bed_' + bedId + '_room_select').hide();
	$('#bed_' + bedId + '_code_input').hide();
	$('#bed_' + bedId + '_maxPatients_select').hide();
	$('#bed_' + bedId + '_price_input').hide();
	$('#bed_' + bedId + '_priceType_select').hide();
	$('#bed_' + bedId + '_save').hide();
	$('#bed_' + bedId + '_cancel').hide();
	
	// show element
	$('#bed_' + bedId + '_department_span').show();
	$('#bed_' + bedId + '_room_span').show();
	$('#bed_' + bedId + '_code_span').show();
	$('#bed_' + bedId + '_maxPatients_span').show();
	$('#bed_' + bedId + '_price_span').show();
	$('#bed_' + bedId + '_priceType_span').show();
	$('#bed_' + bedId + '_edit').show();
}

/**
 * Delete one bed.
 * @param bedId The id of bed
 */
function removeBed(bedId) {
	$('#errorBed').html('');
	$.get(
		'../Department/removeOrUndoBed?set_ajax_view',
		{
		bedId: bedId,
		activity: 'remove'
		},
		function(data) {
			$('#bed_' + bedId + '_status_span').addClass("impression");
			$('#bed_' + bedId + '_status_span').html('');
			$('#bed_' + bedId + '_status_span').append(_("Temporary delete"));
			$('#bed_' + bedId + '_remove_span').html('');
			$('#bed_' + bedId + '_remove_span').append(
					'<a href="javascript:undoBed(' + bedId + ')" title="' + _("Reuse") + '">'
				+    	'<img src="../images/unlock_small.png" alt="' + _("Reuse") + '"></img>'  
	            + 	'</a>');
		}
	);
}

/**
 * Undo one bed 
 * @param bedId The id of bed
 */
function undoBed(bedId) {
	$('#errorBed').html('');
	$.get(
		'../Department/removeOrUndoBed?set_ajax_view',
		{
		bedId: bedId,
		activity: 'undo'
		},
		function(data) {
			$('#bed_' + bedId + '_status_span').removeClass("impression");
			$('#bed_' + bedId + '_status_span').html('');
			$('#bed_' + bedId + '_status_span').append(_("In Use"));
			$('#bed_' + bedId + '_remove_span').html('');
			$('#bed_' + bedId + '_remove_span').append(
					'<a href="javascript:removeBed(' + bedId + ')" title="' + _("Delete") + '">'
				+    	'<img src="../images/lock_small.png" alt="' + _("Delete") + '"></img>'  
	            + 	'</a>');
		}
	);
}